<?php
namespace app\admin\validate;

use app\admin\model\Admin;
use think\Validate;

class Login extends Validate
{
    protected $rule = [
        'code' => 'require|captcha',
        'password'=>'require',
        'nickname'=>'require|checkLogin'
       
    ];

    protected $message  =   [
        'code.require' => '验证码错误'
    ];


    protected function checkLogin($value,$rule,$data)
    {
        // $res = Db::table('fly_user')->where('phone',$data['loginName'])->find();

        $res = Admin::get(['nickname'=>$data['nickname']]);

        if(!$res){
            return "用户或者密码错误";
        }

        if($res->password===fly_md5($data['password'])){

            session('nickname',$res->nickname);
            session('aid',$res->aid);
            return true;
        }else{
            return "用户或者密码错误";
        }
    }

}
